// show how to set line attribute.
// 3 basic line attribute: line color, line width, line stipple
// ref. p.87

#include <gl/freeglut.h>
#include <iostream>

#define CASE1    1
#define CASE2    2
#define CASE3    2

#define USE_CASE CASE1

GLint winWidth = 800, winHeight = 600;

static void init(void)
{
	glClearColor(1.0, 1.0, 1.0, 1.0); // white
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	gluOrtho2D(0, (GLdouble)winWidth, 0, (GLdouble)winHeight);
}

/* Define a two-dimensional world-coordinates data type */
typedef struct {
	float x, y;
} wcPt2D;

wcPt2D dataPts[5] = {
	{100, 100}, {200, 200}, {300, 30}, {400, 400}, {500, 500}
};

void linePlot(wcPt2D dataPts[5])
{
	int k;
	glBegin(GL_LINE_STRIP);
	for (k = 0; k < 5; k++) {
		glVertex2f(dataPts[k].x, dataPts[k].y);
	}
	glEnd();

	glFlush();
}

static void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(0.0, 0.0, 0.0);

	glEnable(GL_LINE_STIPPLE);

#if USE_CASE == CASE1
	{
		/* Input first set of (x, y) data values */
		glLineStipple(1, 0x1C47); // Plot a dash-dot, standard-width polyline
		linePlot(dataPts);
	}
#elif USE_CASE == CASE2
	{
		/* Input second set of (x, y) data values */
		glLineStipple(1, 0x00FF); // Plot a dashed, double-width polyline
		glLineWidth(2.0);
		linePlot(dataPts);
	}
#elif USE_CASE == CASE3
	{
		/* Input third set of (x, y) data values */
		glLineStipple(1, 0x0101); // Plot a dotted, triple-width polyline
		glLineWidth(3.0);
		linePlot(dataPts);
	}
#endif

	glDisable(GL_LINE_STIPPLE);
}

static void reshape(int w, int h)
{
	glClearColor(1.0, 1.0, 1.0, 1.0); // white
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	gluOrtho2D(0, (GLdouble)w, 0, (GLdouble)h);
}

int main(int argc, char* argv[])
{
	glutInit(&argc, argv);
	glutInitWindowPosition(10, 50);
	glutInitWindowSize(winWidth, winHeight);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
	glutCreateWindow("Line Attribute");

	init();
	glutDisplayFunc(display);
	glutReshapeFunc(reshape);

	glutMainLoop();
	return 0;
}
